<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/element.css" rel="stylesheet"/>
    <link href="../css/styleindex.css" rel="stylesheet"/>
    <style>
    .layui-laydate{
      width: 100%!important;
    }.layui-laydate-main{
      width: 100%!important;
    }
    .layui-laydate-content table{
      width: 100%!important;
    }.el-input__inner{
      border: 1px solid #dcdfe6;
    }
    </style>
</head>
<body style="background:#EFF0F4;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <div class="x-header-g" id="header">
        <a class="x-header-arrow" @click="api.closeWin()"></a>
        <div class="x-header-t">管理任务</div>
      </div>
      <!--  -->
      <div class="x-trtali-box" id="calali"></div>
      <!--  -->
      <el-table :data="tableDataone" style="margin-top:1rem;" border>
        <el-table-column label="员工" width="80" fixed>
          <template slot-scope="scope">
            {{scope.row.username}}
          </template>
        </el-table-column>
        <el-table-column label="任务类型" width="80">
          <template slot-scope="scope">
            {{scope.row.task_title}}
          </template>
        </el-table-column>
        <el-table-column label="任务名称" width="80">
          <template slot-scope="scope">
            {{scope.row.title}}
          </template>
        </el-table-column>
        <el-table-column label="完成结果" width="100">
          <template slot-scope="scope">
            {{scope.row.res}}
          </template>
        </el-table-column>
        <el-table-column label="完成确认" width="180">
          <template slot-scope="scope">
            <!-- 本人 -->
            <div class="" v-if="scope.row.memberid==memid">
              <el-button type="primary" v-if="scope.row.is_finish=='0'" @click="examok(scope.row.id,scope.row.username)" size="mini">点击确认</el-button>
              <el-button type="success" disabled  v-if="scope.row.is_finish=='1'" size="mini">已完成</el-button>
              <el-button type="danger" disabled  v-if="scope.row.is_finish=='2'" size="mini">未完成</el-button>
            </div>
            <!--  -->
            <div v-else>
              <div v-if="scope.row.is_finish=='0'">未确认</div>
              <el-button type="success" disabled  v-if="scope.row.is_finish=='1'" size="mini">已完成</el-button>
              <el-button type="danger" disabled  v-if="scope.row.is_finish=='2'" size="mini">未完成</el-button>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="自我评价" width="120">
          <template slot-scope="scope">
            <!-- 本人 -->
            <div class="" v-if="scope.row.memberid==memid">
              <el-button type="primary" v-if="scope.row.my_score=='0'" @click="getnumber(scope.row.id,scope.row.username,'1')" size="mini">点击评价</el-button>
              <el-button type="text" disabled  v-else size="mini">{{scope.row.my_score}}分</el-button>
            </div>
            <!--  -->
            <div v-else>
              <div v-if="scope.row.my_score=='0'">未评价</div>
              <el-button type="text" disabled  v-else size="mini">{{scope.row.my_score}}分</el-button>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="上级评价" width="120">
          <template slot-scope="scope">
            <div type="primary" v-if="scope.row.leader_score=='0'" size="mini">未评价</div>
            <el-button type="success" disabled  v-else size="mini">{{scope.row.leader_score}}分</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--  -->
      <div class="x-task-rate">
        <div class="x-task-t">执行力指数：</div>
        <el-rate v-model="actnum" disabled show-score text-color="#058142" :colors="ratecolor" :max="10" :allow-half="ishalf"></el-rate>
      </div>
      <!--  -->
      <el-dialog :title="'请对“'+scoretoasttitle + '”进行打分'" :visible.sync="dialogVisible" width="90%" center="true" close-on-click-modal="false" show-close="false">
        <div class="x-tra-nin">
          <el-input-number v-model="scoredata" @change="getscorenum" :min="1" :max="10" label="描述文字"></el-input-number>
          <div class="x-tra-desc"></div>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="okgetscore">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>

  <script type="text/javascript" src="../script/vue.js"></script>
  <script type="text/javascript" src="../script/element.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/base.js"></script>
  <script type="text/javascript" src="../script/laydate/laydate.js"></script>
	<script>
apiready = function () {
    var ttype = api.pageParam.type;
    var tgetmonth = api.pageParam.timemonth;



    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          activeName: 'first',
          tableDataone:[],
          tableDatatwo:[],
          thtype:'',
          thmonth:'',
          dialogVisible:false,
          scoretoasttitle:'',
          scoredata:5,
          scoretoastid:'',
          timetoast:false,
          timeshowname:'',
          finishtimedata:'',
          timeshowid:'',
          notkey:false,
          isadmin:0,
          evaluate:'',
          memid:'',
          actnum:0,
          value:0,
          ratecolor:['#058142','#058142','#058142','#058142','#058142'],
          ishalf:true,
          actlength:0,

        }
      },
      created:function() {
        var that=this;


      },
      mounted:function(){
        var that=this;
        that.thtype = ttype;
        that.thmonth = tgetmonth;
        laydate.render({
          elem: '#calali',
          position: 'static',
          btns:['now'],
          format:'yyyy-MM-dd',
          value:that.thmonth,
          // theme:'#058142',
          change:function(value,date){
            console.log(value);
            that.thmonth = value;
            that.getdataone()
          }
        });
        that.memid = $api.getStorage('myid');
        that.getdataone()

      },
      methods: {
        //完成考核确认
        examok:function(id,name){
          var that = this;
          api.actionSheet({
              title: '请确认“'+ name + '”是否完成考核',
              cancelTitle: '取消',
              buttons: ['已完成', '未完成']
          }, function(ret, err) {
              var index = ret.buttonIndex;
              console.log(index);// 1 2
              if(index=='1'){
                that.examgoajax(id,index)
              }else if(index=='2'){
                that.examgoajax(id,index)
              }

          });

        },
        //完成考核 提交
        examgoajax:function(id,index){
          let that=this;
          api.ajax({
            url:baseurl+'api/task/setFinish',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                id:id,
                type:index
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.getdataone()


              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //获取打分分数
        getscorenum:function(val){
          var that = this;
          that.scoredata = val;
        },
        //上级评价
        getnumber:function(id,name,type){
          var that = this;
          that.dialogVisible = true;//显示弹窗
          that.scoretoasttitle = name;
          that.scoretoastid = id;
          that.evaluate = type;

        },
        //上级评价提交
        okgetscore:function(){
          let that=this;
          that.dialogVisible = false;//显示弹窗
          api.ajax({
            url:baseurl+'api/task/setScore',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                id:that.scoretoastid,
                type:that.evaluate,
                score:that.scoredata
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.getdataone()


              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //
        getdataone:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/task/mgList',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                date:that.thmonth
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.isadmin = ret.data.is_admin;
                that.tableDataone = ret.data.list;
                //
                that.actnum = 0;
                for(var i=0;i<ret.data.list.length;i++){
                  that.actnum += Number(ret.data.list[i].executive_score)
                  if(ret.data.list[i].executive_score!='0.0'){
                    that.actlength += 1;
                  }
                }
                that.actnum = that.actnum/that.actlength;

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
      }
    })
	}


	</script>
</body>
</html>
